package device

import (
	"strconv"

	"pac/packet"
)

type Cmd uint8

func (c Cmd) IsCmd() {}

const (
	// CmdLogin 设备报告数据
	CmdLoginReq Cmd = 0x00
	CmdLoginRsp Cmd = 0x80

	// CmdReportMeasure 设备报告测量数据
	CmdReportMeasureReq Cmd = 0x01
	CmdReportMeasureRsp Cmd = 0x81

	// CmdReportMeasure 设备报告波形数据
	CmdReportWaveReq Cmd = 0x02
	CmdReportWaveRsp Cmd = 0x82

	// CmdReportInfo 设备报告数据
	CmdReportInfoReq Cmd = 0x03
	CmdReportInfoRsp Cmd = 0x83

	CmdCtlReq Cmd = 0x40
	CmdCtlRsp Cmd = 0xC0
)

var cmdName = map[Cmd]string{
	CmdLoginReq:         "LOGIN REQ",
	CmdLoginRsp:         "LOGIN RSP",
	CmdReportMeasureReq: "REPORT_MEASURE REQ",
	CmdReportMeasureRsp: "REPORT_MEASURE RSP",
	CmdReportWaveReq:    "REPORT_WAVE REQ",
	CmdReportWaveRsp:    "REPORT_WAVE RSP",
	CmdReportInfoReq:    "REPORT_INFO REQ",
	CmdReportInfoRsp:    "REPORT_INFO RSP",
	CmdCtlReq:           "CONTROL REQ",
	CmdCtlRsp:           "CONTROL RSP",
}

func (c Cmd) String() string {
	s, ok := cmdName[c]
	if ok {
		return s
	}
	return strconv.Itoa(int(c))
}

func (c Cmd) Equal(cmd2 packet.Cmd) bool {
	if c2, ok := cmd2.(Cmd); ok {
		return c == c2
	}
	return false
}
